<template>
  <el-dialog title="通知用户列表" :visible.sync="visible" width="1000px" top="5vh" append-to-body>
    <el-form :model="queryParams" ref="queryForm" size="mini" :inline="true">
      <el-form-item label="邮箱:" prop="email">
        <el-input
          v-model="queryParams.email"
          placeholder="请输入邮箱"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="昵称:" prop="nickname">
        <el-input
          v-model="queryParams.nickname"
          placeholder="请输入昵称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-row>
      <el-table :data="userList" height="260px">
        <el-table-column label="邮箱" align="center" prop="email" :show-overflow-tooltip="true" />
        <el-table-column label="昵称" align="center" prop="nickname" :show-overflow-tooltip="true" />
        <el-table-column label="是否已读" align="center" prop="isRead">
          <template slot-scope="scope">
            {{ scope.row.isRead === '0' ? '未读' : '已读' }}
          </template>
        </el-table-column>
        <el-table-column label="创建时间" align="center" prop="createTime">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.createTime) }}</span>
          </template>
        </el-table-column>
        <el-table-column label="是否推送" align="center" prop="isPush">
          <template slot-scope="scope">
            <dict-tag :options="dict.type['is_push']" :value="scope.row.isPush"/>
          </template>
        </el-table-column>
        <el-table-column label="推送通道" align="center" prop="pushChannel">
          <template slot-scope="scope">
            <dict-tag :options="dict.type['push_channel']" :value="scope.row.pushChannel"/>
          </template>
        </el-table-column>
        <el-table-column label="理由" align="center" prop="failReason" :show-overflow-tooltip="true" />
      </el-table>
      <pagination
        v-show="total>0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
    </el-row>
  </el-dialog>
</template>

<script>
import { noticeMemberPageList } from '@/api/triones/notice'
export default {
  dicts: ['is_push','push_channel'],
  data() {
    return {
      visible: false,
      total: 0,
      userList: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        nid: undefined,
        email: undefined,
        nickname: undefined
      }
    };
  },
  methods: {
    // 显示弹框
    show(id) {
      this.queryParams.nid = id;
      this.getList();
      this.visible = true;
    },
    // 查询表数据
    getList() {
      noticeMemberPageList(this.queryParams).then(res => {
        this.userList = res.rows;
        this.total = res.total;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    }
  }
};
</script>
